#ifndef ADC_HPP
#define ADC_HPP
#include <stdint.h>
#include <stdbool.h>
#include "sdk_config.h"
#include "hc32_ddl.h"
#include "semaphore.hpp"

namespace device
{
	class adc  ///> ADC 类
	{
		public:
			typedef void (*ConvertedCallBack)(uint16_t *usResult, uint16_t usLen);
		
			typedef enum
			{
#if ADC1_ENABLED == 1
				ADC_INSTANCE_1 = 0,
#endif
#if ADC2_ENABLED == 1
				ADC_INSTANCE_2 = 1,
#endif
			}AdcInstanceTPDF;
			
		private:
			uint8_t mAdcChannelLen;
			systemos::semaphore *mAdcSemaphore;
			AdcInstanceTPDF mAdcInstance;
			uint32_t mDmaHandle;
			M4_ADC_TypeDef *mInstance;
		
		public:
			typedef enum
			{
				ADC_CHANNEL_0 = 0x0001,
				ADC_CHANNEL_1 = 0x0002,
				ADC_CHANNEL_2 = 0x0004,
				ADC_CHANNEL_3 = 0x0008,
				ADC_CHANNEL_4 = 0x0010,
				ADC_CHANNEL_5 = 0x0020,
				ADC_CHANNEL_6 = 0x0040,
				ADC_CHANNEL_7 = 0x0080,
				ADC_CHANNEL_8 = 0x0100,
				ADC_CHANNEL_9 = 0x0200,
				ADC_CHANNEL_10 = 0x0400,
				ADC_CHANNEL_11 = 0x0800,
				ADC_CHANNEL_12 = 0x1000,
				ADC_CHANNEL_13 = 0x2000,
				ADC_CHANNEL_14 = 0x4000,
				ADC_CHANNEL_15 = 0x8000,
			}AdcChannelTPDF;
			
			uint32_t Channel;
			uint32_t Frequnce;
			uint32_t SampleLen;
			ConvertedCallBack ConvertCompleteCallBack;
			uint16_t* Buff;
			uint16_t CurrentIndex;
			
			adc(AdcInstanceTPDF tInstance);
			~adc(void);
			bool Start(void);
			void Stop(void);
	};
}

#endif
